package com.work.demo.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.work.demo.model.*;
import com.work.demo.service.IWorkOrderService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 工单 接口
 *
 * @author Wang Yu Hang
 * @date 2024-08-20
 */
@RestController
@RequestMapping("/post/order")
public class WorkOrderController {

    @Autowired
    IWorkOrderService workOrderService;

    /**
     * 单条查询工单
     *
     * @param workOrder
     * @return
     */
    @GetMapping("/searchById/{id}")
    public R list(@PathVariable Integer id) {
        WorkOrder workOrder = workOrderService.getById(id);
        return R.ok().put("result", workOrder);
    }

    /**
     * 分页查询工单
     *
     * @param workOrder
     * @return
     */
    @GetMapping("/search")
    public R list(@RequestBody WorkOrder workOrder) {
        Page<WorkOrder> page = new Page<>(workOrder.getPageNum(), workOrder.getPageSize());
        // 条件构造
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.select();
        IPage iPage = workOrderService.pageMaps(page, wrapper);
        return R.ok().put("result", iPage.getRecords());
    }
}

